package com.lanjiu.lib.imclient.user;

import android.text.TextUtils;

import com.lanjiu.lib.imclient.ims.IMSContacts;
import com.lanjiu.lib.utils.sp.SharedPreferenceHelper;
import com.ljkj.cordial.chat.base.ChatApp;
import com.ljkj.cordial.chat.dao.UserTableBean;

/**
 * @description:
 * @author: Panwei
 * @date: 2019/11/14 17:59
 */
public class UserPreferences {

    private final static String SP_NAME = "user_preferences_name";
    public final static String KAY_TOKEN = "user_token_key";

    // 用户Token
    private static String token;

    public static String getUserId() {
        return ChatApp.getInstance().getUserId();
    }

    public static boolean isRegistered() {
        return ChatApp.getInstance().isRegister();
    }

    public static boolean isRegistered(String userType) {
        return IMSContacts.UserType.REGISTERED_USER.equals(userType);
    }

    public static String getUserType() {
        return ChatApp.getInstance().getUserType();
    }

    public static String getToken() {
        if (TextUtils.isEmpty(token))
            token = SharedPreferenceHelper.create(SP_NAME).getString(KAY_TOKEN);
        if (TextUtils.isEmpty(token))
            token = "";
        return token;
    }

    public static void setToken(String token) {
        UserPreferences.token = token;
        SharedPreferenceHelper.create(SP_NAME).setString(KAY_TOKEN, token);
    }

    public static String getNickname() {
        UserTableBean u = ChatApp.getInstance().get();
        return u != null ? u.getNickname() : "";
//        return (String) SharedUtils.get(ChatApp.getInstance(), Canstants.KEY_Nickname, "");
    }

    public static String getAvatar() {
        UserTableBean u = ChatApp.getInstance().get();
        return u != null ? u.getAvatar() : "";
//        return (String) SharedUtils.get(ChatApp.getInstance(), Canstants.KEY_Avatar, "");
    }
}
